package com.ijunfu.detail.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

/**
 *
 * @Title  : newFixedThreadPool
 * @Author : ijunfu <ijunfu@163.com>
 * @Date   : 2023/11/24 14:20
 * @Version: 1.0
 * @Motto  : 世界很大 世界很小
 *
 */
@Slf4j
public class _02Main {

    public static void main(String[] args) {

        // 1. 创建线程池
        ExecutorService pool = Executors.newFixedThreadPool(5);

        // 2. 使用线程池-业务逻辑
        IntStream.range(0,10).forEach((idx)->pool.execute(()->log.info("No.{}", idx)));

        // 3. 销毁线程池-等待所有任务执行完毕后，关闭线程池
        pool.shutdown();
    }
}
